-
-
Notifications
You must be signed in to change notification settings - Fork 746
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WIP: Implement h2 protocol #1026
Conversation
Merge "encode:master" into h2_impl
^ So that some discussion could be started. |
# Resolved Conflicts: # tests/test_config.py # uvicorn/config.py # uvicorn/protocols/http/h11_impl.py
@@ -20,6 +20,7 @@ types-pyyaml | |||
trustme | |||
cryptography | |||
coverage | |||
starlette |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need starlette
? What's the idea here?
@@ -47,6 +47,7 @@ def get_packages(package): | |||
"asgiref>=3.3.4", | |||
"click>=7.*", | |||
"h11>=0.8", | |||
"h2>=4.0.0", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We want to do the same as httpx: https://github.com/encode/httpx/blob/ab64f7c41fc0fbe638dd586fecf0689c847109bb/setup.py#L66
# TODO: Implement or Not? | ||
# https://groups.google.com/a/chromium.org/g/blink-dev/c/K3rYLvmQUBY/m/vOWBKZGoAQAJ 😕 # noqa: E501 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should, yep.
So, I'm neither necessarily for or against this, but I do have an alternate perspective that I think is worth sharing/considering. See the discussion in... #1105 |
It may well make sense for us to deliberately limit the scope of Uvicorn to being an HTTP/1.1 server. |
@Vibhu-Agarwal Thanks for the effort here, but I think by #1105 we'll highlight hypercorn as the recommendation for HTTP/2. Sorry for taking so long to act here. |
Closes #47
HTTP Parsing
PR #214
It was great! I've picked a lot of stuff from there.
I've mostly worked on extending the PR, removing bugs and modernizing the code.
I've opted to omit a few implementations though, on which I'd like to have some discussion.
Motivation from Hypercorn's code
I also read the hypercorn's code, which has the implementation for HTTP/2 already. I got a pretty good idea of http2's working from there.
priority
It uses priority to build a priority tree and manage the streams.
I haven't yet implemented this in this PR (as it wasn't, in #214). Should we use it?
If we use it, it will also help in implementing code for handling h2 events like
WindowUpdated
,PriorityUpdated
andRemoteSettingsChanged
(which are currently ignored).stream_buffers
Hypercorn also uses StreamBuffers to handle the data of different streams per connection. This may be due to the fact that h2 doesn't buffer data internally for sending. I'm not sure though, as hypercorn checks the chunk size (before sending) anyway.
I haven't yet implemented this in this PR (as it wasn't, in #214). Should we use it?
Server Push
I wasn't sure if I should go ahead with HTTP Server-Push's implementation or not, as its status is not clear.
Should we support it?
In this PR
Some h2-specific changes in SSL-Context
uvicorn/uvicorn/config.py
Line 215 in a8dcf14
uvicorn/uvicorn/config.py
Lines 116 to 125 in a8dcf14
No websocket support, yet.
Connection: Upgrade
(towebocket
) request raisesh2.exceptions.ProtocolError
here:uvicorn/uvicorn/protocols/http/h2_impl.py
Lines 219 to 221 in b683626
uvicorn/uvicorn/protocols/http/h2_impl.py
Line 111 in b683626
That will have to be handled here:
uvicorn/uvicorn/protocols/http/h2_impl.py
Lines 284 to 285 in b683626
Tests
For some reason,
test_h2c_upgrade_request
is causing failure of some un-related tests in Python3.8 and Python3.9 (runs fine in Python <=3.7). Commit 81f21beManual-Testing: I'm not sure how to manually test this one.
Manual-Testing: I tried this with a POST request using curl. It works. I'm not sure how to replicate it in Python or even get raw HTTP request out of it.
HTTPToolsProtocol
andH11Protocol
,H2Protocol
needs testing for a lot of stuff.get_connected_protocol()
a bit) but got messed up with valid raw HTTP/2 requests and SSL-Context passing. Couldn't debug and get it to work.POST
request. It kinda worked out. So I've added this one in the PR.I haven't tried broken apps and others with exceptions.
WIP
# TODO: Task
and added some comments for decision-related discussion or missing implementation.h2_impl.py
similar tohttptools_impl.py
andh11_impl.py
.Help Needed
I'm just giving it a go. Hope to complete this soon 🤞
Will need reviews, inputs, tests, ideas and a lot of help from everyone 🤗